Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Why do local functions have the "internal" access modifier?

Why does the Roslyn compiler generate local functions with the internal access modifier (in IL, assembly) instead of private?

    private void M()
    {
        bool f = true;
        bool x1() => f;
        static bool x2() => true;
    }
    .method assembly hidebysig static
        bool '<M>g__x1|0_0' (
            valuetype C/'<>c__DisplayClass0_0'& ''
        ) cil managed { ... }

    .method assembly hidebysig static
        bool '<M>g__x2|0_1' () cil managed { ... }

sharplab.io

Docs say that it should be private: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions

Local functions are private methods of a type that are nested in another member.

Because all local functions are private, including an access modifier, such as the private keyword, generates compiler error CS0106

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Looks like code reuse artifact. Roslyn probably uses same code to handle local functions and lambdas, but injects method definitions in different classes.

In case of lambda it injects lambda body to generated closure (DisplayClass) class and it should be internal to be referenced from calling function.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda